package com.wineryviewer.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootLayoutPanel;

public class Wineryviewer implements EntryPoint {
  public void onModuleLoad() {
    final RootLayoutPanel rp = RootLayoutPanel.get();
    final MapPanel mapPanel = new MapPanel();
    rp.add(mapPanel);
    createScriptTag(mapPanel);
  }    
  
  private native void createScriptTag(MapPanel map) /*-{
  var head = document.getElementsByTagName('head').item(0);
  var script = document.createElement('script');
  script.src = "http://usa.visa.com/js/signature-scv-wineries.js";
    script.onerror = function() {
      window.alert("onerror");
    }
    script.onload = function() {
     map.@com.wineryviewer.client.MapPanel::initializeData(Lcom/google/gwt/core/client/JavaScriptObject;)(wineries);
    }
    script.onreadystatechange = function () {
      if (script.readyState == 'loaded' || script.readyState == 'complete') {
        script.onreadystatechange = function () { }
        map.@com.wineryviewer.client.MapPanel::initializeData(Lcom/google/gwt/core/client/JavaScriptObject;)(wineries);
      }
    }
    head.appendChild(script);
  }-*/;
}
